import http from "../utils/http"
import {reactive, ref} from "vue"

const user = reactive({
    login_type: 0, // 登录方式，0，密码登录，1，短信登录
    account: "",  // 登录账号/手机号/邮箱
    password: "", // 登录密码
    remember: false, // 是否记住登录状态
    re_password: "",// 确认密码
    sms_code: "",//
    mobile: "", // 手机号
    sms_btn_text: "发送验证码",//
    interval: null,
    sms_interval: 60,
    login(){
        // 用户登录
        return http.post("/users/login/", {
            "username": this.account,
            "password": this.password,
        })
    },
    check_mobile(){
        // 验证手机号
        return http.get(`/users/mobile/${this.mobile}/`)
    },
    register(){
        // 用户注册
        return http.post("/users/register/", {
            "mobile": this.mobile,
            "password":  this.password,
            "re_password": this.re_password,
            "sms_code": this.sms_code
        })
    },
    send_sms_code(){
        // 发送短信验证码
        return http.get(`/users/sms/${this.mobile}/`)
    }
})

export default user;